package com.hou.service;

import com.hou.dao.ProvinceDao;
import com.hou.pojo.Province;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author shkstart
 * @create 2021-09-20-11:27
 */
@Service
@Transactional
public class ProvinceServiceImpl implements ProvinceService {

    @Autowired
    private ProvinceDao provinceDao;

    // 分页查询
    @Override
    public List<Province> findByPage(Integer page, Integer rows) {
        // 起始数据
        int start = (page - 1) * rows;
        // 查询一页的信息
        return provinceDao.findByPage(start,rows);
    }

    // 所有数据查询
    @Override
    public Integer findTotals() {
        return provinceDao.findTotals();
    }

    // 添加省份
    @Override
    public void saveProvince(Province province) {
        province.setPlacecounts(0);
        provinceDao.save(province);
    }

    // 删除省份
    @Override
    public void deleteProvince(Integer id) {
        provinceDao.delete(id);
    }

    // 显示单条信息
    @Override
    public Province findProvinceById(Integer id) {
        Province province = provinceDao.findById(id);
        return province;
    }

    // 更新省份信息
    @Override
    public void updateProvince(Province province) {
        provinceDao.update(province);
    }

    @Override
    public List<Province> getAllProvince() {
        return provinceDao.getAllProvince();
    }

}
